import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { render, formattingMin, formattingDay } from '/@/utils/common/renderUtils';
//子表列表数据
export const bsTravelgroupTourtravellinefinalbindcarrecordColumns : BasicColumn[] = [
	{
		title: '状态',
		align: "center",
		dataIndex: 'trash',
		customRender: ({ text }) => {
			if (text == true) {
				return '已删除'
			} else {
				return '正常'
			}
		}
	},
	{
		title: '领队状态',
		align: "center",
		dataIndex: 'leaderstats',
		customRender: ({ text }) => {
			if (text == 'WaitDispatch') {
				return '待调度'
			} else if (text == 'DispatchFinish') {
				return '调度完成'
			} else if (text == 'WaitApply') {
				return '待同意'
			}
		}
	},
	{
		title: '车辆状态',
		align: "center",
		dataIndex: 'carstats',
		customRender: ({ text }) => {
			if (text == 'WaitDispatch') {
				return '待调度'
			} else if (text == 'DispatchFinish') {
				return '调度完成'
			}
		}
	},
	/* 	{
			title: '旅游拼团',
			align: "center",
			dataIndex: 'travelgroupid'
		},
		 
		 plateNum: params.plateNum || '',
		 cooperatePhone: params.cooperatePhone || '',
		 cooperaterName: params.cooperaterName || '',
		 driverPhone: params.driverPhone || '',
		 driverName: params.driverName || '',
		 totalSalary: params.totalSalary || '',
		 salaryType: params.salaryType || '',
		 
		 */
	{
		title: '车型',
		align: "center",
		dataIndex: 'carid_dictText'
	},
	{
		title: '司机和搭档信息',
		align: "left",
		dataIndex: 'extinfor',
		width:200,
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			if (o.driverName == '') {
				return '未设置'
			}
			return '司机：' + o.driverName + '-' + o.driverPhone + ' 搭档：' + o.cooperaterName + '-' + o.cooperatePhone + ' 车牌：' + o.plateNum
		}
	},
	{
		title: '领队',
		align: "center",
		dataIndex: 'bindleaderid_dictText'
	},
	{
		title: '领队工资',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			if (o.salaryType == 'Grade') {
				return '按正常领队等级'
			} else if (o.salaryType == 'Custom') {
				return '单独工资：' + o.totalSalary
			}
		}
	},
	{
		title: '创建时间',
		align: "center",
		dataIndex: 'createtime',
		customRender: ({ text }) => {
			return formattingMin(text)
		}
	},
	{
		title: '车辆绑定的上车点',
		align: "center",
		dataIndex: 'bindstartpoint_dictText'
	},
	{
		title: '可载游客总人数',
		align: "center",
		dataIndex: 'totaltournum'
	},
	{
		title: '备注',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.msg
		}
	},
];
//子表表单数据
export const bsTravelgroupTourtravellinefinalbindcarrecordFormSchema : FormSchema[] = [
	// TODO 子表隐藏字段，目前写死为ID

	{
		label: '',
		field: 'mainId',
		component: 'Input',
		show: false
	},
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '安排车辆',//根据游玩天数搜索车辆
		field: 'carid',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getCarListByDayNum?mainId=' + formModel.mainId }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'leveltitle',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入选择车辆!' },
			];
		},
	},
	{
		label: '车辆状态',
		field: 'carstats',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '待排中', value: 'WaitDispatch' },
				{ label: '已安排', value: 'DispatchFinish' },
			],
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择车辆状态' },
			];
		},
	},
	//如果车辆已安排：则输入司机电话、姓名，车牌
	{
		label: '司机姓名',
		field: 'driverName',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.carstats == 'DispatchFinish'
		},

	},
	{
		label: '司机电话',
		field: 'driverPhone',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.carstats == 'DispatchFinish'
		},

	},
	{
		label: '搭档姓名',
		field: 'cooperaterName',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.carstats == 'DispatchFinish'
		},

	},
	{
		label: '搭档电话',
		field: 'cooperatePhone',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.carstats == 'DispatchFinish'
		},

	},
	{
		label: '车牌',
		field: 'plateNum',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.carstats == 'DispatchFinish'
		},

	},
	{
		label: '选择领队',//选择没有被行程有空并在这个日期没有被安排的领队
		field: 'bindleaderid',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {

			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getLeadersByIsLeisure?mainId=' + formModel.mainId + '&leaderId=' + formModel.bindleaderid }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'phone',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择领队!' },
			];
		},
	},
	{
		label: '领队工资类型',
		field: 'salaryType',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '按等级工资', value: 'Grade' },
				{ label: '自定义工资', value: 'Custom' },
			],
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择领队工资类型' },
			];
		},
	},

	{
		label: '领队带队总工资',
		field: 'totalSalary',
		component: 'Input',
		ifShow: ({ values }) => {
			return values.salaryType == 'Custom'
		},

	},
	{
		label: '选择接送上车点',//多选，搜索有人的上车点
		field: 'bindstartpoint',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//根据大团id获取上车地点
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getUpCarAddressAddApplyUserNum?tourorderrecordid=' + formModel.mainId + '&isOperator=1' }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'address',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						//carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
			}
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入选择上车点（这里只显示10人以上的上车点）!' },
			];
		},
	},
	{
		label: '可载游客总人数',
		field: 'totaltournum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入可载游客总人数!' },
			];
		},
	},
	{
		label: '备注',
		field: 'msg',
		component: 'InputTextArea',
	},
	/* 	{
			label: '其他信息，json格式',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其他信息，json格式!' },
				];
			},
		}, */
];